home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / man / cat.n / Tcl.n < prev    next >
Text File  |  1995-07-25  |  11KB  |  265 lines

  1.  
  2.  
  3.  
  4.      TTTTccccllll((((nnnn))))                       TTTTccccllll (((( ))))                       TTTTccccllll((((nnnn))))
  5.  
  6.  
  7.  
  8.      _________________________________________________________________
  9.  
  10.      NNNNAAAAMMMMEEEE
  11.           Tcl - Summary of Tcl language syntax.
  12.      _________________________________________________________________
  13.  
  14.  
  15.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  16.           The following rules define the syntax and semantics  of  the
  17.           Tcl language:
  18.  
  19.           [1]  A Tcl  script  is  a  string  containing  one  or  more
  20.                commands.    Semi-colons   and   newlines  are  command
  21.                separators unless quoted  as  described  below.   Close
  22.                brackets   are   command   terminators  during  command
  23.                substitution (see below) unless quoted.
  24.  
  25.           [2]  A command is evaluated in two steps.   First,  the  Tcl
  26.                interpreter  breaks the command into _w_o_r_d_s and performs
  27.                substitutions as described below.  These  substitutions
  28.                are  performed  in  the same way for all commands.  The
  29.                first word is used to locate  a  command  procedure  to
  30.                carry  out  the  command,  then all of the words of the
  31.                command are  passed  to  the  command  procedure.   The
  32.                command  procedure  is  free  to  interpret each of its
  33.                words in any way it likes, such as an integer, variable
  34.                name,   list,   or   Tcl  script.   Different  commands
  35.                interpret their words differently.
  36.  
  37.           [3]  Words of a command are separated by white space (except
  38.                for newlines, which are command separators).
  39.  
  40.           [4]  If the  first  character  of  a  word  is  double-quote
  41.                (``"'')  then  the  word  is  terminated  by  the  next
  42.                double-quote   character.    If   semi-colons,    close
  43.                brackets,   or   white   space   characters  (including
  44.                newlines) appear  between  the  quotes  then  they  are
  45.                treated  as  ordinary  characters  and  included in the
  46.                word.  Command substitution, variable substitution, and
  47.                backslash  substitution are performed on the characters
  48.                between the quotes as  described  below.   The  double-
  49.                quotes are not retained as part of the word.
  50.  
  51.           [5]  If the first character of  a  word  is  an  open  brace
  52.                (``{'')  then  the  word  is terminated by the matching
  53.                close brace (``}'').  Braces nest within the word:  for
  54.                each  additional open brace there must be an additional
  55.                close brace (however, if an open brace or  close  brace
  56.                within  the  word is quoted with a backslash then it is
  57.                not counted in locating the matching close brace).   No
  58.                substitutions  are  performed on the characters between
  59.                the braces except for  backslash-newline  substitutions
  60.  
  61.  
  62.  
  63.      Page 1                                          (printed 7/17/95)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      TTTTccccllll((((nnnn))))                       TTTTccccllll (((( ))))                       TTTTccccllll((((nnnn))))
  71.  
  72.  
  73.  
  74.                described  below,  nor  do semi-colons, newlines, close
  75.                brackets,  or   white   space   receive   any   special
  76.                interpretation.   The  word will consist of exactly the
  77.                characters between the outer braces, not including  the
  78.                braces themselves.
  79.  
  80.           [6]  If a word contains an open  bracket  (``['')  then  Tcl
  81.                performs  _c_o_m_m_a_n_d  _s_u_b_s_t_i_t_u_t_i_o_n.  To do this it invokes
  82.                the  Tcl  interpreter  recursively   to   process   the
  83.                characters  following the open bracket as a Tcl script.
  84.                The script may contain any number of commands and  must
  85.                be  terminated  by a close bracket (``]'').  The result
  86.                of the script (i.e. the result of its last command)  is
  87.                substituted  into the word in place of the brackets and
  88.                all of the characters between them.  There may  be  any
  89.                number  of  command  substitutions  in  a  single word.
  90.                Command substitution is not performed on words enclosed
  91.                in braces.
  92.  
  93.           [7]  If a word  contains  a  dollar-sign  (``$'')  then  Tcl
  94.                performs  _v_a_r_i_a_b_l_e  _s_u_b_s_t_i_t_u_t_i_o_n:   the dollar-sign and
  95.                the following characters are replaced in  the  word  by
  96.                the  value of a variable.  Variable substition may take
  97.                any of the following forms:
  98.  
  99.                $$$$_n_a_m_e          _N_a_m_e is the name of a  scalar  variable;
  100.                               the  name is terminated by any character
  101.                               that   isn't   a   letter,   digit,   or
  102.                               underscore.
  103.  
  104.                $$$$_n_a_m_e((((_i_n_d_e_x))))   _N_a_m_e gives the name of an array variable
  105.                               and  _i_n_d_e_x  gives the name of an element
  106.                               within that array.   _N_a_m_e  must  contain
  107.                               only  letters,  digits, and underscores.
  108.                               Command     substitutions,      variable
  109.                               substitutions,       and       backslash
  110.                               substitutions  are  performed   on   the
  111.                               characters of _i_n_d_e_x.
  112.  
  113.                $$$${{{{_n_a_m_e}}}}        _N_a_m_e is the name of a  scalar  variable.
  114.                               It may contain any characters whatsoever
  115.                               except for close braces.
  116.  
  117.           There may be any  number  of  variable  substitutions  in  a
  118.           single  word.   Variable  substitution  is  not performed on
  119.           words enclosed in braces.
  120.  
  121.           [8]  If a backslash  (``\'')  appears  within  a  word  then
  122.                _b_a_c_k_s_l_a_s_h  _s_u_b_s_t_i_t_u_t_i_o_n occurs.  In all cases but those  |
  123.                described  below  the  backslash  is  dropped  and  the  |
  124.                following character is treated as an ordinary character  |
  125.                and included in the word.  This allows characters  such
  126.  
  127.  
  128.  
  129.      Page 2                                          (printed 7/17/95)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      TTTTccccllll((((nnnn))))                       TTTTccccllll (((( ))))                       TTTTccccllll((((nnnn))))
  137.  
  138.  
  139.  
  140.                as  double  quotes, close brackets, and dollar signs to
  141.                be  included  in  words  without   triggering   special
  142.                processing.   The  following  table lists the backslash
  143.                sequences that are handled specially,  along  with  the
  144.                value that replaces each sequence.
  145.  
  146.                \aaaa                                                            ||
  147.                      Audible alert (bell) (0x7).
  148.  
  149.                \bbbb    Backspace (0x8).
  150.  
  151.                \ffff    Form feed (0xc).
  152.  
  153.                \nnnn    Newline (0xa).
  154.  
  155.                \rrrr    Carriage-return (0xd).
  156.  
  157.                \tttt    Tab (0x9).
  158.  
  159.                \vvvv    Vertical tab (0xb).
  160.  
  161.                \<<<<nnnneeeewwwwlllliiiinnnneeee>>>>_w_h_i_t_e_S_p_a_c_e
  162.                      A single space character replaces the  backslash,  |
  163.                      newline,  and  all white space after the newline.  |
  164.                      This backslash sequence is unique in that  it  is  |
  165.                      replaced   in  a  separate  pre-pass  before  the  |
  166.                      command is actually parsed.  This means  that  it  |
  167.                      will  be  replaced  even  when  it occurs between  |
  168.                      braces, and the resulting space will  be  treated  |
  169.                      as  a  word  separator  if  it isn't in braces or  |
  170.                      quotes.
  171.  
  172.                \\    Backslash (``\'').
  173.  
  174.                \_o_o_o  The digits _o_o_o (one, two, or three of them)  give
  175.                      the octal value of the character.
  176.  
  177.                \xxxx_h_h  The hexadecimal digits _h_h  give  the  hexadecimal  |
  178.                      value of the character.  Any number of digits may  |
  179.                      be present.
  180.  
  181.           Backslash substitution is not performed on words enclosed in
  182.           braces, except for backslash-newline as described above.
  183.  
  184.           [9]  If a hash character (``#'') appears at  a  point  where
  185.                Tcl  is expecting the first character of the first word
  186.                of  a  command,  then  the  hash  character   and   the
  187.                characters that follow it, up through the next newline,
  188.                are treated as a  comment  and  ignored.   The  comment
  189.                character  only has significance when it appears at the
  190.                beginning of a command.
  191.  
  192.  
  193.  
  194.  
  195.      Page 3                                          (printed 7/17/95)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      TTTTccccllll((((nnnn))))                       TTTTccccllll (((( ))))                       TTTTccccllll((((nnnn))))
  203.  
  204.  
  205.  
  206.           [10] Each character is processed exactly  once  by  the  Tcl
  207.                interpreter as part of creating the words of a command.
  208.                For example, if  variable  substition  occurs  then  no
  209.                further  substitions  are performed on the value of the
  210.                variable;   the  value  is  inserted  into   the   word
  211.                verbatim.   If  command  substitution  occurs  then the
  212.                nested command is processed entirely by  the  recursive
  213.                call  to  the  Tcl  interpreter;  no  substitutions are
  214.                perfomed  before  making  the  recursive  call  and  no
  215.                additional substitutions are performed on the result of
  216.                the nested script.
  217.  
  218.           [11] Substitutions do not affect the word  boundaries  of  a
  219.                command.  For example, during variable substitution the
  220.                entire value of the variable becomes part of  a  single
  221.                word, even if the variable's value contains spaces.
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                                          (printed 7/17/95)
  262.  
  263.  
  264.  
  265.